<?php
//模型
class CourseTrainInfoModel extends MY_Model {
	function __construct(){
		parent::__construct();
		$this->table = 'course_train_info';
	}
	//分页列表
	function get_list($arr=array(),$page=1,$size=10){
		$where = " WHERE 1 ";		
		$sql  = "SELECT * from ".
				$this->db->dbprefix.$this->table." {$where} ORDER BY addtime DESC LIMIT ".($page-1)*$size .",{$size}";
				
		$query = $this->db->query($sql);
		$res = $query->result_array();
		
		$sql  = "SELECT count(*) AS num from ".$this->db->dbprefix.$this->table."  {$where}";
		$query = $this->db->query($sql);
		$row = $query->row_array();		
		return array('list'=>$res,'count' =>$row['num']);		
	}
	//全部列表
	function get_lists($arr=array()){
		$where = " WHERE 1 ";
		if(isset($arr['tid'])){
			$where .= " and tid='{$arr['tid']}' ";
		}
		$sql  = "select * from ".$this->db->dbprefix.$this->table.$where.' order by stime asc ';
		$query = $this->db->query($sql);
		$res = $query->result_array();
		return $res;		
	}
	//详情
	function get_info($id){
		$sql  = "SELECT * from ".$this->db->dbprefix.$this->table." where id='{$id}' ";
		$query = $this->db->query($sql);
		$row = $query->row_array();			
		return $row;
	}
	//唯一条件获取详情
	function unique_get_info($field,$value){
		$sql  = "select * from ".$this->db->dbprefix.$this->table." where {$field}='{$value}' ";
		$query = $this->db->query($sql);
		$row = $query->row_array();		
		return $row;
	}
	
}

